package stream;

import reference.Student;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author LiuYan
 * @date 2021/11/19 10:28
 */
public class Part10 {
    public static void main(String[] args) {

        List<Student> studentList = Arrays.asList(
                new Student(20, "lisi"),
                new Student(10, "zhangsan"),
                new Student(30, "wangwu"),
                new Student(20, "lisi1"),
                new Student(10, "zhangsan1"),
                new Student(30, "wangwu1"),
                new Student(20, "lisi2"),
                new Student(10, "zhangsan2"),
                new Student(30, "wangwu2"),
                new Student(40, "goudan"),
                new Student(20, "lisi3"),
                new Student(10, "zhangsan4"),
                new Student(30, "wangwu5"),
                new Student(20, "lisi6"),
                new Student(10, "zhangsan7"),
                new Student(30, "wangwu8"),
                new Student(20, "lisi9"),
                new Student(10, "zhangsan22"),
                new Student(30, "wangwu23"),
                new Student(40, "goudan333"));

        Optional<Integer> reduce = studentList.stream().map(Student::getAge).reduce(Integer::sum);
        System.out.println(reduce.get());


        List<Student> collect = studentList.stream().collect(Collectors.toList());
        System.out.println(collect);

        Long collect1 = studentList.stream().collect(Collectors.counting());
        System.out.println(collect1);

        Double collect2 = studentList.stream().collect(Collectors.averagingInt(Student::getAge));
        System.out.println(collect2);

        Integer collect3 = studentList.stream().collect(Collectors.summingInt(Student::getAge));
        System.out.println(collect3);

        Optional<Integer> collect4 = studentList.stream().map(Student::getAge).collect(Collectors.minBy(Integer::compareTo));
        System.out.println(collect4.get());


        Optional<Integer> collect5 = studentList.stream().map(Student::getAge).collect(Collectors.maxBy(Integer::compareTo));
        System.out.println(collect5.get());





    }
}
